package com.mashibing.juc.homeWork;

import java.util.concurrent.Semaphore;

/**
 * 要求：使用两个线程打印A1B2C3D4...Z26
 * 第一个线程打印ABCD...
 * 第二个线程打印123456...
 * @author: Yuanzt
 * @Date: 2021/3/30
 */
public class AlternatePrint {

    static Thread t1 = null ,t2 = null;

    public static void main(String[] args) {
        Semaphore s = new Semaphore(1,true);
        t1=new Thread(()->{
            t2.start();
            for (int i = 0; i < 26; i++) {
                try {
                    t2.join();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("A"+i);
            }
        });

        t2 = new Thread(()->{
            t1.start();
            for (int i = 0; i < 26; i++) {
                try {
                    t1.join();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(i);
            }
        });

    }
}
